package com.zzh.fullscreen;

import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
/**
 *图片旋转，工具类
 * 
 */
public class ImageOperate {
		/**
		 * 旋转图片
		 * @param bufferedImage 要旋转的图片
		 * @param degree 角度
		 * @return 返回旋转之后的图�?
		 */
		public static BufferedImage rotateImage(final BufferedImage bufferedImage,final int degree)
		{
			int w=bufferedImage.getWidth();//获取图片的宽
			int h=bufferedImage.getHeight();
			int type=bufferedImage.getColorModel().getTransparency();
			
			BufferedImage img;
			Graphics2D graphics2d;
			
			(graphics2d=(img=new BufferedImage(w,h,type)).createGraphics()).setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
			
			graphics2d.rotate(Math.toRadians(degree),w/2,h/2);//旋转角度和旋转的中心（相对图片的位置�?
//			graphics2d.setTransform(Tx);
			graphics2d.drawImage(bufferedImage, 0, 0, null);
			graphics2d.dispose();
			return img;
		}
		/** *//** 
	     * 水平翻转图像 
	     *  
	     * @param bufferedimage 目标图像 
	     * @return 
	     */  
	    public static BufferedImage flipImage(final BufferedImage bufferedimage){  
	        int w = bufferedimage.getWidth();// 得到宽度。  
	        int h = bufferedimage.getHeight();// 得到高度。  
	        BufferedImage img;// 空图片。  
	        Graphics2D graphics2d;// 空画笔。  
	        (graphics2d = (img = new BufferedImage(w, h, bufferedimage  
	                .getColorModel().getTransparency())).createGraphics())  
	                .drawImage(bufferedimage, 0, 0, w, h, w, 0, 0, h, null);  
	        graphics2d.dispose();  
	        return img;  
	    }   
	    /** 
	     * 变更图像为指定大小 
	     *  
	     * @param bufferedimage 
	     *            目标图像 
	     * @param w 
	     *            宽 
	     * @param h 
	     *            高 
	     * @return 
	     */  
	    public static BufferedImage resizeImage(final BufferedImage bufferedimage,  
	            final int w, final int h) {  
	        int type= bufferedimage.getColorModel().getTransparency();// 得到透明度。  
	        BufferedImage img;// 空图片。  
	        Graphics2D graphics2d;// 空画笔。  
	        (graphics2d= (img= new BufferedImage(w, h, type))  
	                .createGraphics()).setRenderingHint(  
	                RenderingHints.KEY_INTERPOLATION,  
	                RenderingHints.VALUE_INTERPOLATION_BILINEAR);  
	        graphics2d.drawImage(bufferedimage, 0, 0, w, h, 0, 0, bufferedimage  
	                .getWidth(), bufferedimage.getHeight(), null);  
	        graphics2d.dispose();  
	        return img;  
	    }  
}
